package god.dream.comment.service;

import god.dream.comment.dao.CommentDAO;
import god.dream.comment.model.Comment;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

public class CommentServiceImpl implements CommentService {

	private CommentDAO commentDAO;

	public int addComment(Comment comment) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		String today = sdf.format(cal.getTime());
		comment.setDate(today);
		return commentDAO.insert(comment);
	}

	public Comment findComment(int id) {
		return commentDAO.findComment(id);
	}

	public List<Comment> findCommentList() {
		return commentDAO.findCommentList();
	}

	public List<Comment> findCommentListWithUser( int uid) {
		return commentDAO.findCommentListWithUser(uid);
	}

	public int removeComment(int id) {
		return commentDAO.delete(id);
	}

	public int updateComment(Comment comment) {
		return commentDAO.update(comment);
	}

	public CommentDAO getCommentDAO() {
		return commentDAO;
	}

	public void setCommentDAO(CommentDAO commentDAO) {
		this.commentDAO = commentDAO;
	}

}
